package cn.jingzhuan.element.demo.view.util

import android.content.Context
import android.os.Build


object SettingShared {

    private val TAG = "SettingShared"

    private val KEY_ENABLE_NOTIFICATION = "enableNotification"
    private val KEY_ENABLE_THEME_DARK = "enableThemeDark"
    private val KEY_ENABLE_TOPIC_DRAFT = "enableTopicDraft"
    private val KEY_ENABLE_TOPIC_SIGN = "enableTopicSign"
    private val KEY_ENABLE_TOPIC_RENDER_COMPAT = "enableTopicRenderCompat"
    private val KEY_SHOW_TOPIC_RENDER_COMPAT_TIP = "showTopicRenderCompatTip"

    val DEFAULT_TOPIC_SIGN_CONTENT = "来自酷炫的 [CNodeMD](https://github.com/TakWolf/CNode-Material-Design)"

    fun isEnableNotification(context: Context): Boolean {
        return SharedWrapper.with(context, TAG).getBoolean(KEY_ENABLE_NOTIFICATION, true)
    }

    fun setEnableNotification(context: Context, enable: Boolean) {
        SharedWrapper.with(context, TAG).setBoolean(KEY_ENABLE_NOTIFICATION, enable)
    }

    fun isEnableThemeDark(context: Context): Boolean {
        return SharedWrapper.with(context, TAG).getBoolean(KEY_ENABLE_THEME_DARK, false)
    }

    fun setEnableThemeDark(context: Context, enable: Boolean) {
        SharedWrapper.with(context, TAG).setBoolean(KEY_ENABLE_THEME_DARK, enable)
    }

    fun isEnableTopicDraft(context: Context): Boolean {
        return SharedWrapper.with(context, TAG).getBoolean(KEY_ENABLE_TOPIC_DRAFT, true)
    }

    fun setEnableTopicDraft(context: Context, enable: Boolean) {
        SharedWrapper.with(context, TAG).setBoolean(KEY_ENABLE_TOPIC_DRAFT, enable)
    }

    fun isEnableTopicSign(context: Context): Boolean {
        return SharedWrapper.with(context, TAG).getBoolean(KEY_ENABLE_TOPIC_SIGN, true)
    }

    fun setEnableTopicSign(context: Context, enable: Boolean) {
        SharedWrapper.with(context, TAG).setBoolean(KEY_ENABLE_TOPIC_SIGN, enable)
    }

    fun isEnableTopicRenderCompat(context: Context): Boolean {
        return SharedWrapper.with(context, TAG).getBoolean(KEY_ENABLE_TOPIC_RENDER_COMPAT, Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
    }

    fun setEnableTopicRenderCompat(context: Context, enable: Boolean) {
        SharedWrapper.with(context, TAG).setBoolean(KEY_ENABLE_TOPIC_RENDER_COMPAT, enable)
    }

    fun isShowTopicRenderCompatTip(context: Context): Boolean {
        return SharedWrapper.with(context, TAG).getBoolean(KEY_SHOW_TOPIC_RENDER_COMPAT_TIP, true)
    }

    fun markShowTopicRenderCompatTip(context: Context) {
        SharedWrapper.with(context, TAG).setBoolean(KEY_SHOW_TOPIC_RENDER_COMPAT_TIP, false)
    }

}